<?php
	

defined('_JEXEC') or die();

class NBEventMapsControllerPersonnalisations extends NBEventMapsController
{
	
	function __construct()
	{
		parent::__construct();

		
		$this->registerTask( 'add', 'edit' );
		$this->registerTask( 'unpublish', 	'publish');
	}

	function view()
	{
		JRequest::setVar( 'view', 'personnalisations' );
		JRequest::setVar( 'layout', 'default'  );

		parent::display();
	}

	
	function edit()
	{
		JRequest::setVar( 'view', 'personnalisations' );
		JRequest::setVar( 'layout', 'detail'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	
	function save()
	{
		$post	= JRequest::get('post');
		$model = $this->getModel('personnalisations');
		$returnid=$model->store($post);
		if ($returnid>0) {
			$msg = JText::_( 'NBEVENTMAP_SAVED' );
		} else {
			$msg = JText::_( 'NBEVENTMAP_SAVED_ERROR' );
		}

		$link = 'index.php?option=com_nbeventmap&controller=personnalisations&task=view';
		
		$this->setRedirect($link, $msg);
	}

	
	function apply()
	{
		$post	= JRequest::get('post');
		$model = $this->getModel('personnalisations');
		$returnid=$model->store($post);
		if ($returnid>0) {
			$msg = JText::_( 'NBEVENTMAP_SAVED' );
		} else {
			$msg = JText::_( 'NBEVENTMAP_SAVED_ERROR' );
		}

		$link = 'index.php?option=com_nbeventmap&controller=personnalisations&task=edit&cid[]='.(int)$returnid;
		
		$this->setRedirect($link, $msg);
	}

	
	function remove()
	{
		$model = $this->getModel('personnalisations');
		if(!$model->delete()) {
			$msg = JText::_( 'Error: One or more NBEventMaps could not be Deleted' );
		} else {
			$msg = JText::_( 'NBEventMap(s) Deleted' );
		}

		$this->setRedirect( 'index.php?option=com_nbeventmap&controller=personnalisations&task=view', $msg );
	}

	
	
	function publish()
	{
		$this->setRedirect( 'index.php?option=com_nbeventmap&controller=personnalisations&task=view' );

		
		$db			=& JFactory::getDBO();
		$user		=& JFactory::getUser();
		$cid		= JRequest::getVar( 'cid', array(), 'post', 'array' );
		$task		= JRequest::getCmd( 'task' );
		$publish	= ($task == 'publish');
		$n			= count( $cid );

		if (empty( $cid )) {
			return JError::raiseWarning( 500, JText::_( 'No items selected' ) );
		}

		JArrayHelper::toInteger( $cid );
		$cids = implode( ',', $cid );

		$query = 'UPDATE #__nbeventmap_personnalisation'
		. ' SET published = ' . (int) $publish
		. ' WHERE id IN ( '. $cids .' )'
		;
		$db->setQuery( $query );
		if (!$db->query()) {
			return JError::raiseWarning( 500, $row->getError() );
		}
		$this->setMessage( JText::sprintf( $publish ? 'Items published' : 'Items unpublished', $n ) );

	}
	
	
	function cancel()
	{
		$msg = JText::_( 'Operation Cancelled' );
		$this->setRedirect( 'index.php?option=com_nbeventmap&controller=personnalisations&task=view', $msg );
	}

}
?>
